package com.geline.easyexcel.config;

import com.geline.easyexcel.annotation.EasyExcelScans;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import java.util.List;

/**
 * 解析 @EasyExcelScans
 *
 * @author: mengxin
 * @date: 2024/2/28 15:43
 */
public class RepeatingRegistrar extends EasyExcelRegistrar {

    public void registerBeanDefinitions(AnnotationMetadata annoMeta, BeanDefinitionRegistry registry) {
        AnnotationAttributes mapperScansAttrs = AnnotationAttributes.fromMap(annoMeta.getAnnotationAttributes(EasyExcelScans.class.getName()));
        if (mapperScansAttrs != null) {
            AnnotationAttributes[] annotations = mapperScansAttrs.getAnnotationArray("value");
            for(int i = 0; i < annotations.length; ++i) {
                List<String> scanBasePackages = this.registerBeanDefinitions(annoMeta, annotations[i]);
                for(String pck : scanBasePackages){
                    registerBeanDefinitions(pck);
                }
            }
        }
    }
}
